<?php


namespace App\Http\Controllers\Admin\Api;


use App\Http\Controllers\Controller;
use App\Http\Repositories\Services\IProductSite;
use App\Http\Requests\Admin\ProductSiteInputDTO;
use App\Util\LayUiVo;
use Illuminate\Http\Request;

class ProductSiteController extends Controller
{
    protected $productSiteService;

    public function __construct(
        IProductSite $productSiteService
    )
    {
        $this->productSiteService = $productSiteService;
    }

    public function page(Request $request)
    {
        $search = $request->only(['name']);
        $page = intval($request->get('page',1));
        $size = intval($request->get('limit',1));
        $data = $this->productSiteService->lists($search, $page, $size);
        return response()->json(new LayUiVo(['data' => $data]));
    }

    public function store(ProductSiteInputDTO $inputDTO)
    {
        $this->productSiteService->store($inputDTO);
        return response()->json(new LayUiVo(['message' => __('response.success')]));
    }

    public function update(ProductSiteInputDTO $inputDTO, $id)
    {
        $this->productSiteService->update($inputDTO, $id);
        return response()->json(new LayUiVo(['message' => __('response.success')]));
    }

    public function delete($id)
    {
        $this->productSiteService->delete($id);
        return response()->json(new LayUiVo(['message' => __('response.success')]));
    }
}